package com.neusoft.elmboot.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.neusoft.elmboot.po.Business;
import com.neusoft.elmboot.po.User;

@Mapper
public interface BusinessMapper {

	@Select("select * from business where orderTypeId=#{orderTypeId} order by businessId")
	public List<Business> listBusinessByOrderTypeId(Integer orderTypeId);
	
	@Select("select * from business where businessId=#{businessId}")
	public Business getBusinessById(Integer businessId);
	
	public List<Business> listBusinessByWords(List<String> list);
	
	@Select("select * from business where businessPassId=#{businessPassId} and password=#{password}")
	public Business getBusinessByIdByPass(Business business);
	
	@Select("select count(*) from business where businessPassId=#{businessPassId}")
	public int getBusinessByPassId(String businessPassId);
	
	@Update("update  business set businessName = #{businessName}, businessAddress = #{businessAddress},businessExplain = #{businessExplain},businessImg = #{businessImg},orderTypeId = #{orderTypeId}, starPrice = #{starPrice},deliveryPrice = #{deliveryPrice}, password = #{password} where businessPassId=#{businessPassId}")
	public int saveBusiness(Business business);
	
	
	//往数据库存储私钥，返回标志
	@Insert("insert into business values(null,'0','0','0','0',0,0,0,'0',#{businessPassId},'0',#{privateKey},#{publicKey})")
	public int saveKey(Business business);
	
	//从数据库取私钥，返回私钥
	@Select("select privateKey from business where businessPassId=#{businessPassId}")
	public String getPrivateKey(String businessPassId);

		
	//从数据库取公钥，返回公钥
	@Select("select publicKey from business where businessPassId=#{businessPassId}")
	public String getPublicKey(String businessPassId);
	
	public int updateBusiness(Business business);
	
	@Select("select * from business where businessPassId=#{businessPassId}")
	public Business getEntireBusinessById(String businessPassId);
	
}
